package com.guojian.common.reflect;

import java.util.Date;

import org.springframework.util.Assert;

import com.fasterxml.jackson.databind.util.ClassUtil;

public class ClassUtils {

	public static boolean isCollectionMapOrArray(Object object) {
		Assert.notNull(object, "参数不能为空");
		return ClassUtil.isCollectionMapOrArray(object.getClass());
	}

	public static boolean isCollectionMapOrArray(Class<?> type) {
		return ClassUtil.isCollectionMapOrArray(type);
	}

	/**3种引用类型 Class interface  array 
	 * isPrimitive 判断Class是否为原始类型
	 *  String is primitive type：false
		Boolean is primitive type：false
		boolean is primitive type：true
		byte is primitive type：true
		char is primitive type：true
		short is primitive type：true
		int is primitive type：true
		long is primitive type：true
		float is primitive type：true
		double is primitive type：true
	 * @param type
	 * @return
	 */
	public static boolean isSimpleType(Class<?> type) {
		if (Boolean.class.isAssignableFrom(type) || String.class.isAssignableFrom(type)) {
			return true;
		}

		//基本数据类型int,double
		if (type.isPrimitive()) {
			return true;
		}

		//时间类型
		if (Date.class.isAssignableFrom(type) || java.sql.Date.class.isAssignableFrom(type)) {
			return true;
		}

		//Number [Integer]
		return Number.class.isAssignableFrom(type) || Enum.class.isAssignableFrom(type);
	}

	public static void main(String[] args) {
		System.out.println(double.class.isPrimitive());
		System.out.println(Number.class.isAssignableFrom(Double.class));

	}

}
